package research.ui.editors.tableeditors;

import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import research.entity.Entity;

public class EntityList {

	private List<Entity> values = new LinkedList<Entity>();
	private Set<IEntityTableListener> changeListeners = new HashSet<IEntityTableListener>();

	public EntityList(List<Entity> values) {
		super();
		this.values = values;
	}

	public void add(Entity entity) {
		values.add(entity);
		Iterator<IEntityTableListener> iterator = changeListeners.iterator();
		while (iterator.hasNext())
			((IEntityTableListener) iterator.next()).add(entity);
	}

	public void removeValue(Entity entity) {
		values.remove(entity);
		Iterator<IEntityTableListener> iterator = changeListeners.iterator();
		while (iterator.hasNext())
			((IEntityTableListener) iterator.next()).remove(entity);
	}

	public void valueChanged(Entity entity) {
		Iterator<IEntityTableListener> iterator = changeListeners.iterator();
		while (iterator.hasNext())
			((IEntityTableListener) iterator.next()).update(entity);
	}

	public void removeChangeListener(IEntityTableListener viewer) {
		changeListeners.remove(viewer);
	}

	public void addChangeListener(IEntityTableListener viewer) {
		changeListeners.add(viewer);
	}

	public List<Entity> getEntities() {
		return values;
	}
}
